//
//  HighLightsViewController.m
//  PlayerWorld
//
//  Created by 1 on 16/4/28.
//  Copyright © 2016年 刘成. All rights reserved.
//
#define UISCREEN_WIDTH  [UIScreen mainScreen].bounds.size.width
#define UISCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height
#import "HighLightsViewController.h"
#import "ZLScrolling.h"
#import "AnnouncementmaiViewController.h"
#import "QuickRechargeViewController.h"
#import "LightningLiftViewController.h"
#import "BettingRecordViewController.h"
#import "CustomViewController.h"
#import "OneOfThePopularColorViewController.h"
#import "HotColorSpeciesTwoViewController.h"
#import "HotColorSpeciesThreeViewController.h"
#import "HotColorSpeciesFourViewController.h"
#import "HighLight2TableViewCell.h"
#import "PLFiveViewController.h"
#import "AFNetworking.h"
#import "HighLightsModel.h"
#import "ChoosePlayViewController.h"
//#import "UIButton+WebCache.h"
#import "UIImageView+WebCache.h"
#import "AccountDetailsViewController.h"
#import "ProcurementHallViewController.h"
#import "YouhuiViewController.h"
@interface HighLightsViewController ()<ZLScrollingDelegate>

@end

@implementation HighLightsViewController
{
    HighLightsModel *model;

}


-(void)obtainData
{
    // 启动系统风火轮
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;

    //服务器给的域名
    NSString *domainStr = @"http://666.lefun6.com/";

    //创建一个可变字典
    NSMutableDictionary *parametersDic = [NSMutableDictionary dictionary];
    //往字典里面添加需要提交的参数
    [parametersDic setObject:@"User" forKey:@"Model"];
    [parametersDic setObject:@"GetUserInfo" forKey:@"Action"];
    [parametersDic setObject:@"yes" forKey:@"r"];

    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];

    //以post的形式提交，POST的参数就是上面的域名，parameters的参数是一个字典类型，将上面的字典作为它的参数
    [manager POST:domainStr parameters:parametersDic progress:^(NSProgress * _Nonnull uploadProgress) {

    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        // 解析成功隐藏系统风火轮
        [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];

        model = [[HighLightsModel alloc]init];
        [model setValuesForKeysWithDictionary:[dic objectForKey:@"userinfo"]];
        
        // 存储到NSUserDefaults
        NSData *data = [NSKeyedArchiver archivedDataWithRootObject:model];
        [[NSUserDefaults standardUserDefaults] setObject:data forKey:@"uid"];
        
        [highlightstableView reloadData];

    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

        // 解析失败隐藏系统风火轮(可以打印error.userInfo查看错误信息)
        [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
        
    }];
    
}

- (void)viewWillAppear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden = NO;
    [self obtainData];
}

- (void)viewDidLoad {
    [super viewDidLoad];

    [self obtainData];
    UILabel *atitlelabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 120, 30)];
    atitlelabel.text = @"精 彩 推 荐";
    atitlelabel.textAlignment = NSTextAlignmentCenter;
    atitlelabel.font = [UIFont boldSystemFontOfSize:17];
    atitlelabel.textColor = [UIColor whiteColor];
    self.navigationItem.titleView = atitlelabel;
    self.navigationController.navigationBar.translucent = NO;
    self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:self action:nil];
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:36/255.0f green:11/255.0f blue:54/255.0f alpha:1];
    self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor]};
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"礼物"] style:UIBarButtonItemStylePlain target:self action:@selector(liwuAction:)];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"首页4"] style:UIBarButtonItemStylePlain target:self action:@selector(perFormAdd:)];
    
    // highlightstableView
    highlightstableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, UISCREEN_WIDTH, UISCREEN_HEIGHT-49) style:UITableViewStylePlain];
    highlightstableView.dataSource = self;
    highlightstableView.delegate = self;
    highlightstableView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self.view addSubview:highlightstableView];
    [self ZLScrolling];
 
}
// 精彩推荐头试图
-(void)ZLScrolling{
    NSArray *url = @[@"http://static.public.ms/lf/Template/Skin_1/images/banner/LF-banner-001.jpg", @"http://static.public.ms/lf/Template/Skin_1/images/banner/LF-banner-002.jpg", @"http://static.public.ms/lf/Template/Skin_1/images/banner/LF-banner-003.jpg", @"http://static.public.ms/lf/Template/Skin_1/images/banner/LF-banner-004.jpg", @"http://static.public.ms/lf/Template/Skin_1/images/banner/LF-banner-005.jpg"];
    NSMutableArray *urlarr = [NSMutableArray array];
    for (NSString *str in url) {
        NSURL *imurl = [NSURL URLWithString:str];
        [urlarr addObject:imurl];
    }
    UIImage *placeholder = [UIImage imageNamed:@"timeline_image_loading.png"];
    ZLScrolling *zl = [[ZLScrolling alloc] initWithCurrentController:self frame:CGRectMake(0, 0, UISCREEN_WIDTH, 150) photos:urlarr placeholderImage:placeholder];
    zl.timeInterval = 5;
    zl.pageControl.pageIndicatorTintColor = [UIColor blackColor];
    zl.delegate= self;
    highlightstableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 150)];
    [highlightstableView.tableHeaderView addSubview:zl.view];
    [highlightstableView registerNib:[UINib nibWithNibName:@"HighLight2TableViewCell" bundle:nil] forCellReuseIdentifier:@"HighLightsTableViewCell"];
}
// 导航右侧按钮点击事件
-(void)perFormAdd:(id)paramSender{

    AnnouncementmaiViewController *aVVC= [[AnnouncementmaiViewController alloc] init];
    [self.navigationController pushViewController:aVVC animated:YES];
}

- (void)zlScrolling:(ZLScrolling *)zlScrolling clickAtIndex:(NSInteger)index
{
    NSLog(@"点击到------%ld",(long)index);
}
- (CGFloat)tableView:(UITableView *)atableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 450;
}

//设置表视图中的行数
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 1;
    
}

//设置单元格中的数据
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellIdent = @"HighLightsTableViewCell";
    HighLight2TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdent];
    cell.backgroundColor = [UIColor groupTableViewBackgroundColor];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;


    [cell.userImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://666.lefun6.com/%@",model.U_Head]]];
//    [cell.userLabel setText:model.U_UserName];
    if (model.U_Money != nil) {
    NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:model.U_Money attributes:@{NSForegroundColorAttributeName:[UIColor colorWithRed:255.0/255.0 green:43.0/255.0 blue:80.0/255.0 alpha:1]}];
    
    [string addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:23]} range:NSMakeRange(0, [model.U_Money rangeOfString:@"."].location+1)];
        cell.balancelabel.attributedText = string;
    }
    UITapGestureRecognizer *remenTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(remenTapAction:)];
    [cell.remen addGestureRecognizer:remenTap];

    UITapGestureRecognizer *mingxiTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(mingxiAction:)];
    [cell.zhanghumingxiView addGestureRecognizer:mingxiTap];
    
    UITapGestureRecognizer *gengduoTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gengduoAction:)];
    [cell.gengduo addGestureRecognizer:gengduoTap];
    return cell;
}
- (void)gengduoAction:(UITapGestureRecognizer *)tap
{
    ProcurementHallViewController *viewC = [[ProcurementHallViewController alloc] init];
    [self.navigationController pushViewController:viewC animated:YES];
}
- (void)mingxiAction:(UITapGestureRecognizer *)tap
{
    AccountDetailsViewController *viewC = [[AccountDetailsViewController alloc] init];
    [viewC setHidesBottomBarWhenPushed:YES];
    [self.navigationController pushViewController:viewC animated:YES];
}
- (void)remenTapAction:(UITapGestureRecognizer *)tap
{
    UIView *view = tap.view;
    NSInteger width = view.bounds.size.width;
    NSInteger height = view.bounds.size.height;
    CGPoint point = [tap locationInView:view];
    ChoosePlayViewController *viewC = [[ChoosePlayViewController alloc] init];
    [viewC setHidesBottomBarWhenPushed:YES];
    if (point.x < width/2 && point.y < height/3) {
        viewC.G_N_Id = @"1";
        viewC.name = @"重庆时时彩";
    }
    if (point.x > width/2 && point.y < height/3) {
        viewC.G_N_Id = @"8";
        viewC.name = @"山东11选5";
    }
    if (point.x < width/2 && point.y > height/3 && point.y < height *2/3) {
        viewC.G_N_Id = @"17";
        viewC.name = @"乐丰一分彩";
    }
    if (point.x > width/2 && point.y > height/3 && point.y < height *2/3) {
        viewC.G_N_Id = @"12";
        viewC.name = @"福彩3D";
    }
    if (point.x < width/2 && point.y > height *2/3) {
        viewC.G_N_Id = @"13";
        viewC.name = @"北京赛车";
    }
    if (point.x > width/2 && point.y > height *2/3) {
        viewC.G_N_Id = @"14";
        viewC.name = @"韩国1.5分彩";
    }
    [self.navigationController pushViewController:viewC animated:YES];
}
//集合按钮点击事件
- (void)chooseTheBtnClick:(UIButton *)sender {
    if (sender.tag == 10) {
//        QuickRechargeViewController *qRVC= [[QuickRechargeViewController alloc] init];
//        [self.navigationController pushViewController:qRVC animated:YES];
    UIAlertController *alerView = [UIAlertController alertControllerWithTitle:@"提示信息" message:@"模块暂未开通，敬请期待" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *action = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
    }];
        [alerView addAction:action];
        [self presentViewController:alerView animated:YES completion:nil];

    } else if (sender.tag == 11) {
//        LightningLiftViewController *lLVC = [[LightningLiftViewController alloc]init];
//        [self.navigationController pushViewController:lLVC animated:YES];
        UIAlertController *alerView = [UIAlertController alertControllerWithTitle:@"提示信息" message:@"模块暂未开通，敬请期待" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *action = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {

        }];
        [alerView addAction:action];
        [self presentViewController:alerView animated:YES completion:nil];

    }else{
        BettingRecordViewController *bRVC = [[BettingRecordViewController alloc]init];
        [self.navigationController pushViewController:bRVC animated:YES];
    }
}

// 自定义彩种按钮点击跳转方法
- (void)custombuttonTheBtnClick:(UIButton *)sender {
    CustomViewController *cVC= [[CustomViewController alloc] init];
    [self.navigationController pushViewController:cVC animated:YES];
}
// 热门彩种一按钮点击跳转方法
- (void)colorbutton1TheBtnClick {
    ChoosePlayViewController *view = [[ChoosePlayViewController alloc] init];
    view.G_N_Id = @"1";
    view.name = @"重庆时时彩";
    [view setHidesBottomBarWhenPushed:YES];
    [self.navigationController pushViewController:view animated:YES];
}

// 热门彩种二按钮点击跳转方法
- (void)colorbutton2TheBtnClick {
    
    ChoosePlayViewController *view = [[ChoosePlayViewController alloc] init];
    view.G_N_Id = @"8";
    view.name = @"山东11选5";
    [view setHidesBottomBarWhenPushed:YES];
    [self.navigationController pushViewController:view animated:YES];
}
// 热门彩种三按钮点击跳转方法
- (void)colorbutton3TheBtnClick:(UIButton *)sender {
    
//    HotColorSpeciesThreeViewController *hCSTVC= [[HotColorSpeciesThreeViewController alloc] init];
//    [self.navigationController pushViewController:hCSTVC animated:YES];
    ChoosePlayViewController *view = [[ChoosePlayViewController alloc] init];
    view.G_N_Id = @"16";
    view.name = @"快乐二分彩";
    [view setHidesBottomBarWhenPushed:YES];
    [self.navigationController pushViewController:view animated:YES];
//    PLFiveViewController *cHDVC= [[PLFiveViewController alloc] init];
//    cHDVC.G_N_Id = @"16";
//    [cHDVC setHidesBottomBarWhenPushed:YES];
//    [self.navigationController pushViewController:cHDVC animated:YES];
    
}
// 热门彩种四按钮点击跳转方法
- (void)colorbutton4TheBtnClick:(UIButton *)sender {
    
//    HotColorSpeciesFourViewController *hCSFVC= [[HotColorSpeciesFourViewController alloc] init];
//    [self.navigationController pushViewController:hCSFVC animated:YES];
//    PLFiveViewController *cHDVC= [[PLFiveViewController alloc] init];
//    cHDVC.G_N_Id = @"4";
//    [cHDVC setHidesBottomBarWhenPushed:YES];
//    [self.navigationController pushViewController:cHDVC animated:YES];
    ChoosePlayViewController *view = [[ChoosePlayViewController alloc] init];
    view.G_N_Id = @"4";
    view.name = @"快乐五分彩";
    [view setHidesBottomBarWhenPushed:YES];
    [self.navigationController pushViewController:view animated:YES];
}


//单元格点击方法
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
//    NSLog(@"qwe");
}
- (void)liwuAction:(UIBarButtonItem *)btn
{
    YouhuiViewController *viewC = [[YouhuiViewController alloc] init];
    [viewC setHidesBottomBarWhenPushed:YES];
    [self.navigationController pushViewController:viewC animated:YES];
}
@end
